//
//  GxProfileViewController.swift
//  microblog
//
//  Created by 记忆不为 on 16/9/17.
//  Copyright © 2016年 记忆不为. All rights reserved.
//

import UIKit

class GxProfileViewController: UIViewController {
    // MARK: - 属性
    let visitorViewY : CGFloat = 180
    
    override func loadView() {
        if isLogin {
            self.view = tableView
        }else{
            self.view = scrollView
            scrollView.delegate = self
            scrollView.backgroundColor = UIColor(white: 237 / 255.0, alpha: 1)
            self.automaticallyAdjustsScrollViewInsets = false
            unLoginView()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "设置", style: .plain, target: self, action: #selector(setting))
    }
    
    // MARK: - 私有方法
    private func unLoginView(){
        profileView.frame = CGRect(x: 0, y: 64, width: UIScreen.width, height: 400)
        self.view.addSubview(profileView)
        //访客视图
        visitorView.frame = CGRect(x: 0, y: visitorViewY , width: UIScreen.width, height: UIScreen.height - visitorViewY)
        self.view.addSubview(visitorView)
        visitorView.delegate = self
        scrollView.contentSize = CGSize(width: 0, height:visitorView.frame.maxY + 5)
    }
    
    //导航栏点击方法
    func setting() ->  Void{
        
    }
    
    // MARK: - 未登录界面懒加载
    private lazy var tableView : UITableView = UITableView()
    private lazy var scrollView : UIScrollView = UIScrollView()
    lazy var profileView : GxSpringView = GxSpringView()
    lazy var visitorView : GxUnLoginView = {
        let view = GxUnLoginView()
        view.setupVisitorInfo(image:"", title: "登录后,你的微博、相册、个人资料会显示在这里，展示给别人")
        return view
    }()
    
    
}

extension GxProfileViewController:UIScrollViewDelegate,GxUnLoginViewDelegate{
    
    // MARK: - scrollView代理方法
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        let scale = scrollView.contentOffset.y / 250.0
        if scale <= 0 {
            self.visitorView.frame.origin.y = visitorViewY - scale * (profileView.frame.maxY - visitorViewY)
            
        }
    }

    
    func registerDidClick() {
        
    }
    func loginDidClick() {
        self.present(UINavigationController(rootViewController: GxOauthViewController()), animated: true, completion: nil)
    }
    
}
